//
//  ZYCVersonDescriptionsView.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/26.
//

#import "ZYCVersonDescriptionsView.h"
#import "BTTitleImageButton.h"
#import "ZYCCheckVersionUpdateView.h"
@interface ZYCVersonDescriptionsView()

@property (nonatomic, strong) UIImageView *logoImageView;
@property (nonatomic, strong) ZYCCheckVersionUpdateView *updateView;
@property (nonatomic, strong) BTTitleImageButton *updatesButton;
@end
@implementation ZYCVersonDescriptionsView

#pragma mark - init
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        [self addSubview:self.logoImageView];
        [self addSubview:self.appNameLabel];
        [self addSubview:self.appVersonLabel];
        [self addSubview:self.updateView];
        [self addSubview:self.updatesButton];
        
        
        self.updatesButton.hidden = YES;

        [self setupConstraints];
    }
    return self;
}


#pragma mark - getters

- (UIImageView *)logoImageView {
    if (!_logoImageView) {
        _logoImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo"]];
    }
    return _logoImageView;
}

- (UILabel *)appNameLabel {
    if (!_appNameLabel) {
        _appNameLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 18.0f) titleColor:HEX_RGB(kTitleThemeColor) textAlignment:ZZTextAlignmentCenter];
    }
    return _appNameLabel;
}

- (UILabel *)appVersonLabel {
    if (!_appVersonLabel) {
        _appVersonLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 18.0f) titleColor:HEX_RGB(kTitleThemeColor) textAlignment:ZZTextAlignmentCenter];
    }
    return _appVersonLabel;
}

- (ZYCCheckVersionUpdateView *)updateView {
    if (!_updateView) {
        _updateView = [[ZYCCheckVersionUpdateView alloc] init];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTap:)];
        [_updateView addGestureRecognizer:tap];
    }
    return _updateView;
}


- (BTTitleImageButton *)updatesButton {
    if (!_updatesButton) {
        _updatesButton = [BTTitleImageButton buttonWithType:UIButtonTypeCustom];
        [_updatesButton setTitle:@"历史版本" forState:UIControlStateNormal];
        [_updatesButton setTitleColor:HEX_RGB(@"#999999") forState:UIControlStateNormal];
        _updatesButton.titleLabel.font = kCustomFont(@"PingFangSC-Regular", 15.0f);
        [_updatesButton setImage:[UIImage imageNamed:@"more"] forState:UIControlStateNormal];
        [_updatesButton addTarget:self action:@selector(clickUpdateAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _updatesButton;
}



#pragma mark - 点击事件
- (void)clickUpdateAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(versionDescriptionsViewDidHistoryVersion)]) {
        [self.delegate versionDescriptionsViewDidHistoryVersion];
    }
}

- (void)clickTap:(UIGestureRecognizer *)tap{
    if ([self.delegate respondsToSelector:@selector(versionDescriptionViewDidUpdateVersion)]) {
        [self.delegate versionDescriptionViewDidUpdateVersion];
    }
}

#pragma mark - 约束
- (void)setupConstraints{

    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(133.0f, 133.0f));
        make.centerX.equalTo(self);
        make.top.equalTo(self).offset(63.0f);
    }];
    
    [self.appNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.logoImageView.mas_bottom).offset(30.0f);
    }];
    [self.appVersonLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.appNameLabel.mas_bottom).offset(11.0f);
    }];
    
    [self.updateView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.appVersonLabel.mas_bottom).offset(11.0f);
        make.height.mas_equalTo(45.0f);
    }];
    
    [self.updatesButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.bottom.equalTo(self).offset(-57.0f);
    }];
    
}

@end
